#include <cassert> // for assert
#include <cmath> // for fabs
-#include <cstdlib> // for atof, strtod
+#include <cstdlib> // for strtod
#include <cstring> // for strlen, strchr, strncmp, strcmp, memmove, strcpy, strcspn, strncpy
#include <QByteArray> // for QByteArray
// if not N or E, prepend a '-' to ddmm2degrees input
// see XT_LAT_NMEA which handles ddmm directly
if (strchr(ddmmdir, 'W') || strchr(ddmmdir, 'S')) {
- return ddmm2degrees(- atof(ddmmdir));
+ return ddmm2degrees(- strtod(ddmmdir, nullptr));
}
- return ddmm2degrees(atof(ddmmdir));
+ return ddmm2degrees(strtod(ddmmdir, nullptr));
}
void list_codecs();
void list_timezones();
QString grapheme_truncate(const QString& input, unsigned int count);
+int xstrtoi(const char* str, char** str_end, int base);
/*
* From parse.c
#include <QDebug> // for QDebug
#include <QRegularExpression> // for QRegularExpression, QRegularExpression::CaseInsensitiveOption, QRegularExpressionMatch
-#include <cstdlib> // for atoi, atof
+#include <cstdlib> // for strtod
#include "defs.h" // for Waypoint, fatal, route_del_wpt, route_disp_all, track_del_wpt, track_disp_all, waypt_del, waypt_disp_all, route_head, rtedata, trkdata, wptdata, fix_none, fix_unknown
#include "src/core/logging.h" // for FatalMsg
void DiscardFilter::init()
{
if (hdopopt) {
- hdopf = atof(hdopopt);
+ hdopf = strtod(hdopopt, nullptr);
} else {
hdopf = -1.0;
}
if (vdopopt) {
- vdopf = atof(vdopopt);
+ vdopf = strtod(vdopopt, nullptr);
} else {
vdopf = -1.0;
}
if (satopt) {
- satpf = atoi(satopt);
+ satpf = xstrtoi(satopt, nullptr, 10);
} else {
satpf = -1;
}
if (eleminopt) {
- eleminpf = atoi(eleminopt);
+ eleminpf = xstrtoi(eleminopt, nullptr, 10);
}
if (elemaxopt) {
- elemaxpf = atoi(elemaxopt);
+ elemaxpf = xstrtoi(elemaxopt, nullptr, 10);
}
if (nameopt) {
#include <cmath> // for fabs, modf, copysign, round, fmax
#include <cstdint> // for uint32_t, int32_t, uint16_t, int16_t, uint8_t, INT32_MAX
#include <cstdio> // for printf, SEEK_SET, snprintf, SEEK_CUR
-#include <cstdlib> // for labs, atoi
+#include <cstdlib> // for labs
#include <cstring> // for memcmp, strlen
#include <type_traits> // for add_const<>::type
route_disp_all(nullptr, nullptr, exif_find_wpt_by_time_lambda);
waypt_disp_all(exif_find_wpt_by_time_lambda);
- qint64 frame = atoi(opt_frame);
+ qint64 frame = xstrtoi(opt_frame, nullptr, 10);
if (exif_wpt_ref == nullptr) {
warning(MYNAME ": No point with a valid timestamp found.\n");
#include <cmath> // for atan2, floor, sqrt
#include <csetjmp> // for setjmp
#include <cstdio> // for fprintf, fflush, snprintf, sprintf
-#include <cstdlib> // for atoi, strtol
+#include <cstdlib> // for strtol
#include <cstring> // for memcpy, strlen, strncpy, strchr
#include <ctime> // for time_t
* If the user provided a short_length, override the calculated value.
*/
if (snlen) {
- setshort_length(mkshort_handle, atoi(snlen));
+ setshort_length(mkshort_handle, xstrtoi(snlen, nullptr, 10));
} else {
setshort_length(mkshort_handle, receiver_short_length);
}
if (snwhiteopt) {
- setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt));
+ setshort_whitespace_ok(mkshort_handle, xstrtoi(snwhiteopt, nullptr, 10));
}
/*
tx_waylist[i]->time_populated = 1;
}
if (category) {
- tx_waylist[i]->category = 1 << (atoi(category) - 1);
+ tx_waylist[i]->category = 1 << (xstrtoi(category, nullptr, 10) - 1);
}
if (categorybits) {
tx_waylist[i]->category = categorybits;
#include <cassert> // for assert
#include <cstdio> // for snprintf, sscanf
-#include <cstdlib> // for atof
+#include <cstdlib> // for strtod
#include <cstring> // for strncpy
#include <QByteArray> // for QByteArray
switch (tag) {
case 1:
if (*cdatastr) {
- WAYPT_SET(waypt, proximity, atof(cdatastr));
+ WAYPT_SET(waypt, proximity, strtod(cdatastr, nullptr));
}
break;
case 2:
if (*cdatastr) {
- WAYPT_SET(waypt, temperature, atof(cdatastr));
+ WAYPT_SET(waypt, temperature, strtod(cdatastr, nullptr));
}
break;
case 3:
if (*cdatastr) {
- WAYPT_SET(waypt, depth, atof(cdatastr));
+ WAYPT_SET(waypt, depth, strtod(cdatastr, nullptr));
}
break;
case 4:
#include <cctype> // for tolower
#include <cstdint> // for uint32_t, int32_t
#include <cstdio> // for SEEK_CUR, SEEK_SET
-#include <cstdlib> // for atoi
#include <cstring> // for strlen, strncmp
#include <ctime> // for time, gmtime, time_t, tm
#include <memory> // for unique_ptr
gbfclose(fout);
if ((opt_sleep) && !gpsbabel_testmode()) { /* don't sleep during 'testo' */
- int sleep = atoi(opt_sleep);
+ int sleep = xstrtoi(opt_sleep, nullptr, 10);
if (sleep < 1) {
sleep = 1;
}
#include <cmath> // for fabs, floor
#include <cstdio> // for NULL, snprintf, sscanf
#include <cstdint>
-#include <cstdlib> // for atoi, abs
+#include <cstdlib> // for abs
#include <cstring> // for memset, strstr, strcat, strchr, strlen, strcmp, strcpy, strncpy
#include <ctime> // for gmtime, localtime, strftime
gtxt_flags.celsius = (toupper(*get_option_val(opt_temp, "c")) == 'C');
init_date_and_time_format();
if (opt_precision) {
- precision = atoi(opt_precision);
+ precision = xstrtoi(opt_precision, nullptr, 10);
if (precision < 0) {
fatal(MYNAME ": Invalid precision (%s)!", opt_precision);
}
if (case_ignore_strcmp(opt_utc, "utc") == 0) {
utc_offs = 0;
} else {
- utc_offs = atoi(opt_utc);
+ utc_offs = xstrtoi(opt_utc, nullptr, 10);
}
utc_offs *= (60 * 60);
gtxt_flags.utc = 1;
}
break;
case 9:
- WAYPT_SET(wpt, course, atoi(CSTR(str)));
+ WAYPT_SET(wpt, course, xstrtoi(CSTR(str), nullptr, 10));
break;
}
}
*/
#include "defs.h"
-#include <cstdlib>
#define MYNAME "Garmin_XT"
#define GARMIN_XT_ELE 31500/65536
// get the option for the processing the track name
if (opt_trk_header) {
- method = atoi(opt_trk_header);
+ method = xstrtoi(opt_trk_header, nullptr, 10);
// if method is out of range set to default
if ((method < 0) || (method > 1)) {
method = 0;
// get the option for the processing the track name
if (opt_trk_header) {
- method = atoi(opt_trk_header);
+ method = xstrtoi(opt_trk_header, nullptr, 10);
}
if (! track) {
#include <cmath> // for fabs
#include <cstdio> // for printf, snprintf, sscanf, SEEK_SET
-#include <cstdlib> // for atoi, strtol
+#include <cstdlib> // for strtol
#include <cstring> // for memset, strstr, strchr, strcmp, strlen, strncpy
#include <ctime> // for strftime, tm
#include <iterator> // for next
fout = gbfopen_le(fname, "wb", MYNAME);
ftmp = gbfopen_le(nullptr, "wb", MYNAME);
- gdb_category = (gdb_opt_category) ? atoi(gdb_opt_category) : 0;
- gdb_ver = (gdb_opt_ver && *gdb_opt_ver) ? atoi(gdb_opt_ver) : 0;
+ gdb_category = (gdb_opt_category) ? xstrtoi(gdb_opt_category, nullptr, 10) : 0;
+ gdb_ver = (gdb_opt_ver && *gdb_opt_ver) ? xstrtoi(gdb_opt_ver, nullptr, 10) : 0;
if (gdb_category) {
if ((gdb_category < 1) || (gdb_category > 16)) {
GdbFormat::write()
{
if (gdb_opt_ver) {
- gdb_ver = atoi(gdb_opt_ver);
+ gdb_ver = xstrtoi(gdb_opt_ver, nullptr, 10);
}
write_header();
{
fnamestr = fname;
trk_count = 0;
- splitfiles = splitfiles_opt ? atoi(splitfiles_opt) : 0;
+ splitfiles = splitfiles_opt ? xstrtoi(splitfiles_opt, nullptr, 10) : 0;
/* If writing to stdout, never split files */
if (0 == strcmp("-",splitfiles_opt)) {
fout = gbfopen(ofname, "wb", MYNAME);
}
if (wayptspd && wayptspd[0]) {
- gpssim_write_spd(atof(wayptspd));
+ gpssim_write_spd(strtod(wayptspd, nullptr));
}
waypt_disp_all(gpssim_write_pt);
if (splitfiles) {
#include <cmath> // for lround
#include <cstdio> // for sscanf
-#include <cstdlib> // for atoi, strtod
+#include <cstdlib> // for strtod
#include <cstring> // for strchr, strncpy
#include <QDate> // for QDate
setshort_whitespace_ok(mkshort_handle, 0);
}
- setshort_length(mkshort_handle, atoi(snlen));
+ setshort_length(mkshort_handle, xstrtoi(snlen, nullptr, 10));
}
void
GpxFormat::write()
{
- elevation_precision = atoi(opt_elevation_precision);
+ elevation_precision = xstrtoi(opt_elevation_precision, nullptr, 10);
gpx_reset_short_handle();
auto gpx_waypt_pr_lambda = [this](const Waypoint* waypointp)->void {
#include <cstdarg> // for va_end, va_list, va_start
#include <cstdio> // for snprintf
-#include <cstdlib> // for atoi
#include <iterator> // for size
#include <optional> // for optional
#include <type_traits> // for add_const<>::type
}
}
}
- gtc_course_flag = atoi(opt_course);
+ gtc_course_flag = xstrtoi(opt_course, nullptr, 10);
}
void
#include <climits> // for INT_MAX
#include <cmath> // for abs, ceil, isfinite, round
-#include <cstdlib> // for abs, atoi, strtod
+#include <cstdlib> // for abs, strtod
#include <optional> // for optional
#include <QString> // for QString
if (0 == strcmp(portname+4, "list")) {
req_unit_number = -1;
} else {
- req_unit_number = atoi(portname + 4);
+ req_unit_number = xstrtoi(portname + 4, nullptr, 10);
}
}
return garmin_usb_scan(lud, req_unit_number);
if (0 == strcmp(pname+4, "list")) {
req_unit_number = -1;
} else {
- req_unit_number = atoi(pname+4);
+ req_unit_number = xstrtoi(pname+4, nullptr, 10);
}
}
#include <cctype> // for tolower, toupper
#include <cmath> // for fabs
#include <cstdio> // for sscanf, printf
-#include <cstdlib> // for atoi, atol, atof
+#include <cstdlib> // for strtod
#include <cstring> // for strcmp
#include <optional> // for optional
#include <tuple> // for tuple, make_tuple, tie
void KmlFormat::kml_init_color_sequencer(unsigned int steps_per_rev)
{
if (rotate_colors) {
- float color_step = atof(opt_rotate_colors);
+ float color_step = strtod(opt_rotate_colors, nullptr);
if (color_step > 0.0f) {
// step around circle by given number of degrees for each track(route)
kml_color_sequencer.step = ((float)kml_color_limit) * 6.0f * color_step / 360.0f;
posnfilename = fname;
posnfilenametmp = QStringLiteral("%1-").arg(fname);
realtime_positioning = 1;
- max_position_points = atoi(opt_max_position_points);
+ max_position_points = xstrtoi(opt_max_position_points, nullptr, 10);
}
void KmlFormat::wr_deinit()
if (export_points) {
writer->writeStartElement(QStringLiteral("Placemark"));
- if (atoi(opt_labels)) {
+ if (xstrtoi(opt_labels, nullptr, 10)) {
writer->writeOptionalTextElement(QStringLiteral("name"), waypointp->shortname);
}
writer->writeEmptyElement(QStringLiteral("snippet"));
rotate_colors = (!! opt_rotate_colors);
trackdata = (!! strcmp("0", opt_trackdata));
trackdirection = (!! strcmp("0", opt_trackdirection));
- line_width = atol(opt_line_width);
- precision = atol(opt_precision);
+ line_width = xstrtoi(opt_line_width, nullptr, 10);
+ precision = xstrtoi(opt_precision, nullptr, 10);
writer->writeStartDocument();
#include <cmath> // for M_PI, round, atan, exp, log, tan
#include <cstdio> // for printf, sprintf, SEEK_CUR
#include <cstdint> // for int64_t
-#include <cstdlib> // for atoi, abs
+#include <cstdlib> // for abs
#include <cstring> // for strcmp, strlen
#include <QByteArray> // for QByteArray
file_out = gbfopen_le(fname, "wb", MYNAME);
mkshort_handle = mkshort_new_handle();
waypt_out_count = 0;
- writing_version = atoi(opt_wversion);
+ writing_version = xstrtoi(opt_wversion, nullptr, 10);
if ((writing_version < 2) || (writing_version > 4)) {
fatal(MYNAME " wversion value %s is not supported !!\n", opt_wversion);
}
gbfputc(0, file_out);
/* device serial number */
- opt_serialnum_i = atoi(opt_serialnum);
+ opt_serialnum_i = xstrtoi(opt_serialnum, nullptr, 10);
gbfputint32(opt_serialnum_i, file_out);
/* content description */
#include <cctype> // for isprint, toupper
#include <cmath> // for fabs, lround
#include <cstdio> // for sscanf, size_t
-#include <cstdlib> // for atoi, atof, strtoul
+#include <cstdlib> // for strtod, strtoul
#include <cstring> // for strchr, strncmp, strlen, memmove, strrchr, memset
#include <QByteArray> // for QByteArray
}
if (bs) {
- bitrate=atoi(bs);
+ bitrate=xstrtoi(bs, nullptr, 10);
}
if (!mkshort_handle) {
{
suppress_ack = 0;
if (bs) {
- bitrate=atoi(bs);
+ bitrate=xstrtoi(bs, nullptr, 10);
}
if (waypt_count() > 500) {
}
if (cmts) {
- wptcmtcnt_max = atoi(cmts);
+ wptcmtcnt_max = xstrtoi(cmts, nullptr, 10);
} else {
wptcmtcnt_max = MAXCMTCT ;
}
* for us.
*/
parse_istring(trkmsg);
- double latdeg = atof(ifield[1]);
+ double latdeg = strtod(ifield[1], nullptr);
char latdir = ifield[2][0];
- double lngdeg = atof(ifield[3]);
+ double lngdeg = strtod(ifield[3], nullptr);
char lngdir = ifield[4][0];
- int alt = atof(ifield[5]);
+ int alt = strtod(ifield[5], nullptr);
char altunits = ifield[6][0];
(void)altunits;
sscanf(ifield[7], "%d.%d", &hms, &fracsecs);
/* Field 8 is constant */
/* Field nine is optional track name */
- int dmy = atoi(ifield[10]);
+ int dmy = xstrtoi(ifield[10], nullptr, 10);
int sec = hms % 100;
hms = hms / 100;
int min = hms % 100;
// check log status - is logging disabled ?
do_cmd(CMD_LOG_STATUS, "PMTK182,3,7,", &lstatus, 2);
if (lstatus) {
- log_status = atoi(lstatus);
+ log_status = xstrtoi(lstatus, nullptr, 10);
dbg(3, "LOG Status '%s'\n", lstatus);
xfree(lstatus);
lstatus = nullptr;
// check log status - is logging disabled ?
do_cmd(CMD_LOG_STATUS, "PMTK182,3,7,", &fusage, 2);
if (fusage) {
- log_enabled = (atoi(fusage) & 2)?1:0;
+ log_enabled = (xstrtoi(fusage, nullptr, 10) & 2)?1:0;
dbg(3, "LOG Status '%s' -- log %s \n", fusage, log_enabled?"enabled":"disabled");
xfree(fusage);
fusage = nullptr;
#include <cctype> // for isprint
#include <cmath> // for fabs
#include <cstdio> // for snprintf, sscanf, fprintf, fputc, stderr
-#include <cstdlib> // for atoi, atof, strtod
+#include <cstdlib> // for strtod
#include <cstring> // for strncmp, strchr, strlen, strstr, memset, strrchr
#include <iterator> // for operator!=, reverse_iterator
sleepms = -1;
if (opt_sleep) {
if (*opt_sleep) {
- sleepms = 1e3 * atof(opt_sleep);
+ sleepms = 1e3 * strtod(opt_sleep, nullptr);
} else {
sleepms = -1;
}
}
mkshort_handle = mkshort_new_handle();
- setshort_length(mkshort_handle, atoi(snlenopt));
+ setshort_length(mkshort_handle, xstrtoi(snlenopt, nullptr, 10));
if (opt_gisteq) {
opt_gpgga = nullptr;
gbser_flush(gbser_handle);
if (opt_baud) {
- if (!gbser_set_speed(gbser_handle, atoi(opt_baud))) {
+ if (!gbser_set_speed(gbser_handle, xstrtoi(opt_baud, nullptr, 10))) {
fatal(MYNAME ": Unable to set baud rate %s\n", opt_baud);
}
}
#include <cctype> // for tolower
#include <cmath> // for lround
-#include <cstdlib> // for atoi
#include <QByteArray> // for QByteArray
#include <QChar> // for operator==, QChar
/* set mkshort options from the command line if applicable */
if (global_opts.synthesize_shortnames) {
- setshort_length(mkshort_handle, atoi(snlenopt));
+ setshort_length(mkshort_handle, xstrtoi(snlenopt, nullptr, 10));
if (snwhiteopt) {
- setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt));
+ setshort_whitespace_ok(mkshort_handle, xstrtoi(snwhiteopt, nullptr, 10));
}
if (snupperopt) {
- setshort_mustupper(mkshort_handle, atoi(snupperopt));
+ setshort_mustupper(mkshort_handle, xstrtoi(snupperopt, nullptr, 10));
}
if (snuniqueopt) {
- setshort_mustuniq(mkshort_handle, atoi(snuniqueopt));
+ setshort_mustuniq(mkshort_handle, xstrtoi(snuniqueopt, nullptr, 10));
}
setshort_badchars(mkshort_handle, "\",");
*/
-#include <cstdlib> // for atoi, strtod
+#include <cstdlib> // for strtod
#include <QString> // for QString
#include <QtGlobal> // for qAsConst, QAddConst<>::Type, foreach
}
if (maxctarg != nullptr) {
- maxct = atoi(maxctarg);
+ maxct = xstrtoi(maxctarg, nullptr, 10);
} else {
maxct = 0;
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <cstdlib> // for atoi
#include <random> // for mt19937
#include <QByteArray> // for QByteArray
{
generator = new std::mt19937;
if (opt_seed) {
- generator->seed(atoi(opt_seed));
+ generator->seed(xstrtoi(opt_seed, nullptr, 10));
} else {
generator->seed(gpsbabel_time);
}
Waypoint* prev = nullptr;
QDateTime time = current_time().toUTC();
- int points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1;
+ int points = (opt_points) ? xstrtoi(opt_points, nullptr, 10) : rand_int(128) + 1;
if (doing_trks || doing_rtes) {
head = new route_head;
if (doing_trks) {
random_set_generator();
realtime = new realtime_data;
if (opt_points) {
- realtime->points = atoi(opt_points);
+ realtime->points = xstrtoi(opt_points, nullptr, 10);
}
realtime->time = current_time().toUTC();
}
#include <cmath> // for cos, sin, atan2, pow, sqrt, M_PI
#include <cstdarg> // for va_end, va_list, va_start
#include <cstdio> // for sscanf, snprintf, vprintf, SEEK_SET
-#include <cstdlib> // for atoi, free
+#include <cstdlib> // for free
#include <cstring> // for memset
#include <ctime> // for time, time_t
*/
time_t gps_timet = 315964800; /* Jan 06 1980 0:00 UTC */
- int week_rollover = atoi(opt_gps_week_rollover);
+ int week_rollover = xstrtoi(opt_gps_week_rollover, nullptr, 10);
if (week_rollover < 0) {
int current_week = (time(nullptr)-gps_timet)/(7*SECONDS_PER_DAY);
week_rollover = current_week/1024 - (week > current_week%1024 ? 1 : 0);
}
gps_timet += (week+week_rollover*1024)*7*SECONDS_PER_DAY + sec;
- int override = atoi(opt_gps_utc_offset);
+ int override = xstrtoi(opt_gps_utc_offset, nullptr, 10);
if (override) {
gps_timet -= override;
return gps_timet;
rd_char(&errors);
rd_char(&errors);
rd_char(&errors);
- skytraq_set_baud(atoi(opt_dlbaud));
+ skytraq_set_baud(xstrtoi(opt_dlbaud, nullptr, 10));
#endif
cs = skytraq_calc_checksum(buf, i);
uint32_t log_wr_ptr;
uint16_t sectors_free, sectors_total, /*sectors_used_a, sectors_used_b,*/ sectors_used;
int t, rc, got_sectors, total_sectors_read = 0;
- int read_at_once = MAX(atoi(opt_read_at_once), 1);
- int opt_first_sector_val = atoi(opt_first_sector);
- int opt_last_sector_val = atoi(opt_last_sector);
+ int read_at_once = MAX(xstrtoi(opt_read_at_once, nullptr, 10), 1);
+ int opt_first_sector_val = xstrtoi(opt_first_sector, nullptr, 10);
+ int opt_last_sector_val = xstrtoi(opt_last_sector, nullptr, 10);
int multi_read_supported = 1;
gbfile* dumpfile = nullptr;
db(1, MYNAME ": opt_last_sector_val=%d\n", opt_last_sector_val);
for (int i = opt_first_sector_val; i < sectors_used; i += got_sectors) {
for (t = 0, got_sectors = 0; (t < SECTOR_RETRIES) && (got_sectors <= 0); t++) {
- if (atoi(opt_read_at_once) == 0 || multi_read_supported == 0) {
+ if (xstrtoi(opt_read_at_once, nullptr, 10) == 0 || multi_read_supported == 0) {
rc = skytraq_read_single_sector(i, buffer);
if (rc == res_OK) {
got_sectors = 1;
switch (rc) {
case res_OK:
got_sectors = read_at_once;
- read_at_once = MIN(read_at_once*2, atoi(opt_read_at_once));
+ read_at_once = MIN(read_at_once*2, xstrtoi(opt_read_at_once, nullptr, 10));
break;
case res_NACK:
{
int baud_rates[] = { 9600, 230400, 115200, 57600, 4800, 19200, 38400 };
int baud_rates_count = sizeof(baud_rates)/sizeof(baud_rates[0]);
- int initbaud = atoi(opt_initbaud);
+ int initbaud = xstrtoi(opt_initbaud, nullptr, 10);
uint8_t MSG_QUERY_SOFTWARE_VERSION[2] = { 0x02, 0x01 };
struct {
uint8_t id;
return;
}
- int dlbaud = atoi(opt_dlbaud);
+ int dlbaud = xstrtoi(opt_dlbaud, nullptr, 10);
if (dlbaud != 0 && dlbaud != skytraq_baud) {
skytraq_set_baud(dlbaud);
}
{
struct read_state st;
int got_bytes;
- int opt_first_sector_val = atoi(opt_first_sector);
- int opt_last_sector_val = atoi(opt_last_sector);
+ int opt_first_sector_val = xstrtoi(opt_first_sector, nullptr, 10);
+ int opt_last_sector_val = xstrtoi(opt_last_sector, nullptr, 10);
state_init(&st);
auto* buffer = (uint8_t*) xmalloc(SECTOR_SIZE);
*/
-#include <cstdlib> // for atoi
-
#include "defs.h"
#include "stackfilter.h"
}
if (opt_depth) {
- swapdepth = atoi(opt_depth);
+ swapdepth = xstrtoi(opt_depth, nullptr, 10);
}
if (opt_push) {
if (opt_pop || opt_append || opt_discard || opt_replace ||
*/
#include <cctype> // for toupper
-#include <cstdlib> // for atoi
#include <QtGlobal> // for foreach
name_digits = 3;
if (rpt_name_digits && *rpt_name_digits) {
- name_digits = atoi(rpt_name_digits);
+ name_digits = xstrtoi(rpt_name_digits, nullptr, 10);
}
if (opt_waypts != nullptr) {
#include <cmath> // for fabs, lround
#include <cstdio> // for NULL, sscanf
#include <cstdint>
-#include <cstdlib> // for atoi
#include <cstring> // for memset, strchr, strncpy
#include <ctime> // for gmtime
res += *date;
}
if (opt_utc) {
- res += atoi(opt_utc) * SECONDS_PER_HOUR;
+ res += xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR;
} else {
struct tm tm = *gmtime(&res);
res = mklocaltime(&tm);
}
if (opt_utc) {
- wpt->creation_time = wpt->creation_time.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
+ wpt->creation_time = wpt->creation_time.addSecs(xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR);
}
}
}
QDateTime dt = idt;
if (opt_utc) {
- //time += atoi(opt_utc) * SECONDS_PER_HOUR;
- dt = dt.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
+ //time += xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR;
+ dt = dt.addSecs(xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR);
dt = dt.toUTC();
}
if (opt_utc) {
dt = wpt->GetCreationTime().toUTC();
// We might wrap to a different day by overriding the TZ offset.
- dt = dt.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
+ dt = dt.addSecs(xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR);
} else {
dt = wpt->GetCreationTime().toLocalTime();
}
QTime t;
if (opt_utc) {
t = wpt->GetCreationTime().toUTC().time();
- t = t.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
+ t = t.addSecs(xstrtoi(opt_utc, nullptr, 10) * SECONDS_PER_HOUR);
} else {
t = wpt->GetCreationTime().toLocalTime().time();
}
unicsv_datum_idx = gt_lookup_datum_index(opt_datum, MYNAME);
}
- llprec = atoi(opt_prec);
+ llprec = xstrtoi(opt_prec, nullptr, 10);
}
void
}
return output;
}
+
+int xstrtoi(const char* str, char** str_end, int base)
+{
+
+ long value = strtol(str, str_end, base);
+ if (value > INT_MAX) {
+ errno = ERANGE;
+ return INT_MAX;
+ }
+ if (value < INT_MIN) {
+ errno = ERANGE;
+ return INT_MIN;
+ }
+ return value;
+}
#include "defs.h"
#include <cassert>
#include <cstdio>
-#include <cstdlib> // atoi
+#include <cstdlib> // strtod
/* the start of each record (line) is common to both advanced and basic mode.
it will be parsed by a single common code. hence, it will be easier and clearer
/* lat is a string in the form: 31.768380N */
char c = line.bas.common.latitude_NS; /* N/S */
assert(c == 'N' || c == 'S');
- wpt->latitude = atof(line.bas.common.latitude_num);
+ wpt->latitude = strtod(line.bas.common.latitude_num, nullptr);
if (c == 'S') {
wpt->latitude = -wpt->latitude;
}
/* lon is a string in the form: 035.209656E */
c = line.bas.common.longitude_EW; /* get E/W */
assert(c == 'E' || c == 'W');
- line.bas.common.longitude_EW = 0; /* the E will confuse atof(), if not removed */
- wpt->longitude = atof(line.bas.common.longitude_num);
+ line.bas.common.longitude_EW = 0; /* the E will confuse strtod(), if not removed */
+ wpt->longitude = strtod(line.bas.common.longitude_num, nullptr);
if (c == 'W') {
wpt->longitude = -wpt->longitude;
}
- wpt->altitude = atoi(line.bas.common.height);
+ wpt->altitude = xstrtoi(line.bas.common.height, nullptr, 10);
/* handle date/time fields */
{
- int date = atoi(line.bas.common.date);
- int time = atoi(line.bas.common.time);
+ int date = xstrtoi(line.bas.common.date, nullptr, 10);
+ int time = xstrtoi(line.bas.common.time, nullptr, 10);
wpt->SetCreationTime(bintime2utc(date, time));
}
- wpt->speed = KPH_TO_MPS(atoi(line.bas.common.speed));
+ wpt->speed = KPH_TO_MPS(xstrtoi(line.bas.common.speed, nullptr, 10));
wpt->wpt_flags.speed = 1;
- wpt->course = atoi(line.bas.common.heading);
+ wpt->course = xstrtoi(line.bas.common.heading, nullptr, 10);
wpt->wpt_flags.course = 1;
if (is_advanced_mode) {
- wpt->hdop = atof(line.adv.hdop);
- wpt->vdop = atof(line.adv.vdop);
- wpt->pdop = atof(line.adv.pdop);
+ wpt->hdop = strtod(line.adv.hdop, nullptr);
+ wpt->vdop = strtod(line.adv.vdop, nullptr);
+ wpt->pdop = strtod(line.adv.pdop, nullptr);
/* handle fix mode (2d, 3d, etc.) */
if (!strncmp(line.adv.valid,"DGPS", sizeof line.adv.valid)) {
static int get_param_int(const char* cmd)
{
char buf[80];
- return atoi(get_param(cmd, buf, sizeof(buf)));
+ return xstrtoi(get_param(cmd, buf, sizeof(buf)), nullptr, 10);
}
static double get_param_float(const char* cmd)
{
char buf[80];
- return atof(get_param(cmd, buf, sizeof(buf)));
+ return strtod(get_param(cmd, buf, sizeof(buf)), nullptr);
}
/* Decompose binary date into discreet fields */
#include <cctype> // for isdigit, tolower
#include <cmath> // for fabs, pow
#include <cstdio> // for snprintf, sscanf
-#include <cstdlib> // for atof, atoi, strtod
+#include <cstdlib> // for strtod
#include <cstring> // for strlen, strncmp, strcmp, memset
#include <ctime> // for gmtime, localtime, time_t, mktime, strftime
#include <optional> // for optional
/* LATITUDE CONVERSIONS**************************************************/
case XcsvStyle::XT_LAT_DECIMAL:
/* latitude as a pure decimal value */
- wpt->latitude = atof(s);
+ wpt->latitude = strtod(s, nullptr);
break;
case XcsvStyle::XT_LAT_DECIMALDIR:
case XcsvStyle::XT_LAT_DIRDECIMAL:
break;
case XcsvStyle::XT_LAT_INT32DEG:
/* latitude as a 32 bit integer offset */
- wpt->latitude = intdeg_to_dec((int) atof(s));
+ wpt->latitude = intdeg_to_dec((int) strtod(s, nullptr));
break;
case XcsvStyle::XT_LAT_HUMAN_READABLE:
human_to_dec(value, &wpt->latitude, &wpt->longitude, 1);
wpt->latitude = ddmmdir_to_degrees(s);
break;
case XcsvStyle::XT_LAT_NMEA:
- wpt->latitude = ddmm2degrees(atof(s));
+ wpt->latitude = ddmm2degrees(strtod(s, nullptr));
break;
// XT_LAT_10E is handled outside the switch.
/* LONGITUDE CONVERSIONS ***********************************************/
case XcsvStyle::XT_LON_DECIMAL:
/* longitude as a pure decimal value */
- wpt->longitude = atof(s);
+ wpt->longitude = strtod(s, nullptr);
break;
case XcsvStyle::XT_LON_DECIMALDIR:
case XcsvStyle::XT_LON_DIRDECIMAL:
break;
case XcsvStyle::XT_LON_INT32DEG:
/* longitude as a 32 bit integer offset */
- wpt->longitude = intdeg_to_dec((int) atof(s));
+ wpt->longitude = intdeg_to_dec((int) strtod(s, nullptr));
break;
case XcsvStyle::XT_LON_HUMAN_READABLE:
human_to_dec(value, &wpt->latitude, &wpt->longitude, 2);
wpt->longitude = ddmmdir_to_degrees(s);
break;
case XcsvStyle::XT_LON_NMEA:
- wpt->longitude = ddmm2degrees(atof(s));
+ wpt->longitude = ddmm2degrees(strtod(s, nullptr));
break;
// case XcsvStyle::XT_LON_10E is handled outside the switch.
/* LAT AND LON CONVERSIONS ********************************************/
&wpt->latitude, &wpt->longitude, MYNAME);
break;
case XcsvStyle::XT_UTM_ZONE:
- parse_data->utm_zone = atoi(s);
+ parse_data->utm_zone = xstrtoi(s, nullptr, 10);
break;
case XcsvStyle::XT_UTM_ZONEC:
parse_data->utm_zonec = s[0];
break;
case XcsvStyle::XT_UTM_ZONEF:
- parse_data->utm_zone = atoi(s);
+ parse_data->utm_zone = xstrtoi(s, nullptr, 10);
parse_data->utm_zonec = s[strlen(s) - 1];
break;
case XcsvStyle::XT_UTM_EASTING:
- parse_data->utm_easting = atof(s);
+ parse_data->utm_easting = strtod(s, nullptr);
break;
case XcsvStyle::XT_UTM_NORTHING:
- parse_data->utm_northing = atof(s);
+ parse_data->utm_northing = strtod(s, nullptr);
break;
case XcsvStyle::XT_UTM: {
char* ss;
/* PATH CONVERSIONS ************************************************/
case XcsvStyle::XT_PATH_SPEED:
- WAYPT_SET(wpt, speed, atof(s));
+ WAYPT_SET(wpt, speed, strtod(s, nullptr));
break;
case XcsvStyle::XT_PATH_SPEED_KPH:
- WAYPT_SET(wpt, speed, KPH_TO_MPS(atof(s)));
+ WAYPT_SET(wpt, speed, KPH_TO_MPS(strtod(s, nullptr)));
break;
case XcsvStyle::XT_PATH_SPEED_MPH:
- WAYPT_SET(wpt, speed, MPH_TO_MPS(atof(s)));
+ WAYPT_SET(wpt, speed, MPH_TO_MPS(strtod(s, nullptr)));
break;
case XcsvStyle::XT_PATH_SPEED_KNOTS:
- WAYPT_SET(wpt, speed, KNOTS_TO_MPS(atof(s)));
+ WAYPT_SET(wpt, speed, KNOTS_TO_MPS(strtod(s, nullptr)));
break;
case XcsvStyle::XT_PATH_COURSE:
- WAYPT_SET(wpt, course, atof(s));
+ WAYPT_SET(wpt, course, strtod(s, nullptr));
break;
/* TIME CONVERSIONS ***************************************************/
case XcsvStyle::XT_EXCEL_TIME:
/* Time as Excel Time */
- wpt->SetCreationTime(excel_to_timet(atof(s)));
+ wpt->SetCreationTime(excel_to_timet(strtod(s, nullptr)));
break;
case XcsvStyle::XT_TIMET_TIME: {
/* Time as time_t */
/* GEOCACHING STUFF ***************************************************/
case XcsvStyle::XT_GEOCACHE_DIFF:
/* Geocache Difficulty as an int */
- wpt->AllocGCData()->diff = atof(s) * 10;
+ wpt->AllocGCData()->diff = strtod(s, nullptr) * 10;
break;
case XcsvStyle::XT_GEOCACHE_TERR:
/* Geocache Terrain as an int */
- wpt->AllocGCData()->terr = atof(s) * 10;
+ wpt->AllocGCData()->terr = strtod(s, nullptr) * 10;
break;
case XcsvStyle::XT_GEOCACHE_TYPE:
/* Geocache Type */
/* GPS STUFF *******************************************************/
case XcsvStyle::XT_GPS_HDOP:
- wpt->hdop = atof(s);
+ wpt->hdop = strtod(s, nullptr);
break;
case XcsvStyle::XT_GPS_VDOP:
- wpt->vdop = atof(s);
+ wpt->vdop = strtod(s, nullptr);
break;
case XcsvStyle::XT_GPS_PDOP:
- wpt->pdop = atof(s);
+ wpt->pdop = strtod(s, nullptr);
break;
case XcsvStyle::XT_GPS_SAT:
- wpt->sat = atoi(s);
+ wpt->sat = xstrtoi(s, nullptr, 10);
break;
case XcsvStyle::XT_GPS_FIX:
- wpt->fix = (fix_type)(atoi(s)-(fix_type)1);
+ wpt->fix = (fix_type)(xstrtoi(s, nullptr, 10)-(fix_type)1);
if (wpt->fix < fix_2d) {
if (!case_ignore_strcmp(value, "none")) {
wpt->fix = fix_none;
parse_data->rte_name = csv_stringtrim(value, enclosure, 0);
break;
case XcsvStyle::XT_TRACK_NEW:
- parse_data->new_track = atoi(s);
+ parse_data->new_track = xstrtoi(s, nullptr, 10);
break;
case XcsvStyle::XT_TRACK_NAME:
parse_data->trk_name = csv_stringtrim(value, enclosure, 0);
/* OTHER STUFF ***************************************************/
case XcsvStyle::XT_PATH_DISTANCE_METERS:
- wpt->odometer_distance = atof(s);
+ wpt->odometer_distance = strtod(s, nullptr);
break;
case XcsvStyle::XT_PATH_DISTANCE_KM:
- wpt->odometer_distance = atof(s) * 1000.0;
+ wpt->odometer_distance = strtod(s, nullptr) * 1000.0;
break;
case XcsvStyle::XT_PATH_DISTANCE_MILES:
- wpt->odometer_distance = MILES_TO_METERS(atof(s));
+ wpt->odometer_distance = MILES_TO_METERS(strtod(s, nullptr));
break;
case XcsvStyle::XT_PATH_DISTANCE_NAUTICAL_MILES:
- wpt->odometer_distance = NMILES_TO_METERS(atof(s));
+ wpt->odometer_distance = NMILES_TO_METERS(strtod(s, nullptr));
break;
case XcsvStyle::XT_HEART_RATE:
- wpt->heartrate = atoi(s);
+ wpt->heartrate = xstrtoi(s, nullptr, 10);
break;
case XcsvStyle::XT_CADENCE:
- wpt->cadence = atoi(s);
+ wpt->cadence = xstrtoi(s, nullptr, 10);
break;
case XcsvStyle::XT_POWER:
- wpt->power = atof(s);
+ wpt->power = strtod(s, nullptr);
break;
case XcsvStyle::XT_TEMPERATURE:
- wpt->temperature = atof(s);
+ wpt->temperature = strtod(s, nullptr);
break;
case XcsvStyle::XT_TEMPERATURE_F:
- wpt->temperature = (FAHRENHEIT_TO_CELSIUS(atof(s)));
+ wpt->temperature = (FAHRENHEIT_TO_CELSIUS(strtod(s, nullptr)));
break;
/* GMSD ****************************************************************/
case XcsvStyle::XT_COUNTRY: {
break;
case XcsvStyle::XT_unused:
if (strncmp(fmp.key.constData(), "LON_10E", 7) == 0) {
- wpt->longitude = atof(s) / pow(10.0, atof(fmp.key.constData()+7));
+ wpt->longitude = strtod(s, nullptr) / pow(10.0, strtod(fmp.key.constData()+7, nullptr));
} else if (strncmp(fmp.key.constData(), "LAT_10E", 7) == 0) {
- wpt->latitude = atof(s) / pow(10.0, atof(fmp.key.constData()+7));
+ wpt->latitude = strtod(s, nullptr) / pow(10.0, strtod(fmp.key.constData()+7, nullptr));
} else {
warning(MYNAME ": Unknown style directive: %s\n", fmp.key.constData());
}
buff = QString::asprintf(fmp.printfc.constData(), "");
break;
case XcsvStyle::XT_INDEX:
- buff = QString::asprintf(fmp.printfc.constData(), waypt_out_count + atoi(fmp.val.constData()));
+ buff = QString::asprintf(fmp.printfc.constData(), waypt_out_count + xstrtoi(fmp.val.constData(), nullptr, 10));
break;
case XcsvStyle::XT_CONSTANT: {
auto cp = XcsvStyle::xcsv_get_char_from_constant_table(fmp.val.constData());
break;
case XcsvStyle::XT_unused:
if (strncmp(fmp.key.constData(), "LON_10E", 7) == 0) {
- buff = QString::asprintf(fmp.printfc.constData(), lon * pow(10.0, atof(fmp.key.constData()+7)));
+ buff = QString::asprintf(fmp.printfc.constData(), lon * pow(10.0, strtod(fmp.key.constData()+7, nullptr)));
} else if (strncmp(fmp.key.constData(), "LAT_10E", 7) == 0) {
- buff = QString::asprintf(fmp.printfc.constData(), lat * pow(10.0, atof(fmp.key.constData()+7)));
+ buff = QString::asprintf(fmp.printfc.constData(), lat * pow(10.0, strtod(fmp.key.constData()+7, nullptr)));
}
break;
default:
if (global_opts.synthesize_shortnames) {
if (snlenopt) {
- setshort_length(xcsv_file->mkshort_handle, atoi(snlenopt));
+ setshort_length(xcsv_file->mkshort_handle, xstrtoi(snlenopt, nullptr, 10));
}
if (snwhiteopt) {
- setshort_whitespace_ok(xcsv_file->mkshort_handle, atoi(snwhiteopt));
+ setshort_whitespace_ok(xcsv_file->mkshort_handle, xstrtoi(snwhiteopt, nullptr, 10));
}
if (snupperopt) {
- setshort_mustupper(xcsv_file->mkshort_handle, atoi(snupperopt));
+ setshort_mustupper(xcsv_file->mkshort_handle, xstrtoi(snupperopt, nullptr, 10));
}
if (snuniqueopt) {
- setshort_mustuniq(xcsv_file->mkshort_handle, atoi(snuniqueopt));
+ setshort_mustuniq(xcsv_file->mkshort_handle, xstrtoi(snuniqueopt, nullptr, 10));
}
setshort_badchars(xcsv_file->mkshort_handle, CSTR(xcsv_style->badchars));